package com.lu.minio.config;


import com.lu.minio.service.FileStorageService;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@EnableConfigurationProperties({MinIoConfigProperties.class})
@ConditionalOnClass(FileStorageService.class)
public class MinIoConfig {
    @Autowired
    private MinIoConfigProperties minioConfigProperties;

    @Bean
    public MinioClient getMinioClient() {
        return MinioClient.builder()
                          .credentials(minioConfigProperties.getAccessKey(), minioConfigProperties.getSecretKey())
                          .endpoint(minioConfigProperties.getEndpoint()).build();
    }
}
